//
//  XJYMTTeiZiDetailViewController.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/6.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  帖子详情

#import "XJYMTTeiZiDetailViewController.h"

// view
#import "CommonMenuView.h"

#import "XJTieZiDetailView.h"
// VC
#import "XJJuBaoTieZiViewController.h" // 举报

#import <UShareUI/UShareUI.h>
#import "LMJUMengHelper.h"

@interface XJYMTTeiZiDetailViewController ()
@property (nonatomic,assign) BOOL flag; // 用于标记menu的状态
@property(nonatomic, strong) XJTieZiDetailView *detailView;

@end

@implementation XJYMTTeiZiDetailViewController



- (XJTieZiDetailView *)detailView {
    if (!_detailView) {
//        _detailView = [[XJTieZiDetailView alloc] initWithFrame:CGRectMake(0, 0, KWidth, KHeight)];
        
        _detailView = [[XJTieZiDetailView alloc] initWithFrame:CGRectMake(0, XJTopNavH, KWidth, KHeight - XJTopNavH)];
    }
    return _detailView;
}

#pragma mark - 二 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupNavAndMenu];
    
    [self setupView];
}


- (void)setupNavAndMenu {
    [self setupNav];
    
    [self setupMenu];
}
- (void)setupView {
    
    self.detailView.tieZiId = self.tieZiId; // 请求参数1,将网络请求放到 view层。
    self.detailView.type = self.type;
    
    [self.view addSubview:self.detailView];
    [self.detailView tieZiDetailViewRequestData]; // 对象创建好之后在进行网络请求
}



#pragma mark - 三 右上角菜单
- (void)setupMenu {
    self.flag = YES; //默认真第一次就可以点击。
    NSDictionary *dict1 = @{@"imageName" : @"address_edit",
                            @"itemName" : @"分享"
                            };
    NSDictionary *dict2 = @{@"imageName" : @"address_edit",
                            @"itemName" : @"举报"
                            };

    NSArray *dataArray = @[dict1,dict2];
    
    __weak __typeof(&*self)weakSelf = self;
    /**
     *  创建普通的MenuView，frame可以传递空值，宽度默认120，高度自适应
     */
    [CommonMenuView createMenuWithFrame:CGRectZero target:self dataArray:dataArray itemsClickBlock:^(NSString *str, NSInteger tag) {
        XJLog(@"%ld",tag);
        [weakSelf doSomething:(NSString *)str tag:(NSInteger)tag]; // do something
    } backViewTap:^{
        weakSelf.flag = YES; // 这里的目的是，让rightButton点击，可再次pop出menu
    }];
}
- (void)setupNav{
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"address_edit"] style:(UIBarButtonItemStylePlain) target:self action:@selector(popMenuAction)];
}

- (void)popMenuAction{
    CGFloat h = 50;

    if (self.view.frame.size.height > 736.0) {
        h = 60;
    }
    [self popMenu:CGPointMake(self.navigationController.view.width - 30, h)];
}
- (void)popMenu:(CGPoint)point{
    if (self.flag) {
        [CommonMenuView showMenuAtPoint:point];
        self.flag = NO;
    }else{
        [CommonMenuView hidden];
        self.flag = YES;
    }
}


#pragma mark -- 回调事件(自定义)
- (void)doSomething:(NSString *)str tag:(NSInteger)tag{
 
    if (tag == 1) {
        [self shareTiezi];
    }else if(tag == 2){
        [self juBaoTieZi];
    }else {
        XJLog(@"其他操作");
    }
    
    [CommonMenuView hidden];
    self.flag = YES;
}


#pragma mark - 右上角弹出菜单 点击事件
- (void)shareTiezi {
    XJLog(@"分享帖子操作");
    
    [self showMiddleNormalView];
}

- (void)showMiddleNormalView
{
    [UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewPostionType = UMSocialSharePageGroupViewPositionType_Middle;
    
    [LMJUMengHelper shareTitle:@"新疆商城" subTitle:@"谢谢使用!欢迎交流!" thumbImage:@"https://avatars2.githubusercontent.com/u/18454795?s=400&u=c8a7cc691e5c3611e9fb49dcf9c83843dd9141a2&v=4" shareURL:@"https://www.github.com/njhu"];
}

- (void)juBaoTieZi {
    XJLog(@"举报帖子");

    // 网路请求放在view层。
    XJJuBaoTieZiViewController *juBaoVC = [[XJJuBaoTieZiViewController alloc] init];
    juBaoVC.invitation_id = self.tieZiId;
    
    [self.navigationController pushViewController:juBaoVC animated:YES];
}


@end
